import os
import time
from datetime import datetime
import shutil
import asyncio
import sys

def modify_file_extension(folder_path, old_extension, new_extension):
    for root, dirs, files in os.walk(folder_path):
        for file in files:
            if file.endswith(old_extension):
                old_file_path = os.path.join(root, file)
                new_file_path = os.path.join(root, file.rsplit('.', 1)[0] + '.' + new_extension)
                os.rename(old_file_path, new_file_path)
                print(f"Renamed file: {old_file_path} -> {new_file_path}")

# 示例用法
folder_path = '/path/to/folder'  # 指定文件夹路径
old_extension = '.txt'  # 原后缀名
new_extension = '.csv_diff'  # 新后缀名

modify_file_extension(folder_path, old_extension, new_extension)


async def main():
    if len(sys.argv) < 2:
        print(f"------请设置要清除的目录-----")
    else:
        root_dir = sys.argv[1]
        old_extension = sys.argv[2]
        new_extension = sys.argv[3]
        modify_file_extension(root_dir, old_extension, new_extension)


if __name__ == '__main__':
    asyncio.run(main())
